
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
import time

service = Service(executable_path='D:\\chromedriver.exe')
driver = webdriver.Chrome(service=service)
driver.maximize_window()

# 打开url
driver.get("https://quotes.toscrape.com/")
time.sleep(1)

# 找到登录入口
login_entry = driver.find_element(By.XPATH, '//a[@href="/login"]')
# 点击web元素
login_entry.click()
time.sleep(1)

username_input = driver.find_element(By.ID, 'username')
username_input.send_keys("admin")
time.sleep(1)

password_input = driver.find_element(By.ID, 'password')
password_input.send_keys("123456")
time.sleep(1)

submit_btn = driver.find_element(By.XPATH, '//input[@type="submit"]')
submit_btn.click()
time.sleep(1)

logout_entry = driver.find_element(By.CSS_SELECTOR, '.col-md-4>p>a')
logout_entry.click()
time.sleep(5)


driver.quit()


